/**
 * Created with IntelliJ IDEA.
 * Description: 字符串转整数
 */
public class Test2 {
    public int StrToInt(String str) {
        if(str.length() == 0) {
            return 0;
        }
        int flg = 1;
        int i = 0;
        if(str.charAt(0) == '-') {
            flg = -1;
            i++;
        }else if(str.charAt(0) == '+'){
            i++;
        }
        int num = 0;
        for(; i < str.length(); i++) {
            if(str.charAt(i) >= '0' && str.charAt(i) <= '9') {
                num = num * 10 + (str.charAt(i) - '0');
            }else {
                return 0;
            }
        }
        return flg * num;
    }
}
